home *** CD-ROM | disk | FTP | other *** search
/ Compendium Deluxe 1 / LSD Compendium Deluxe 1.iso / a / text / manipulation / text2scp.lha / text2scp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-03  |  1.7 KB  |  105 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define TRUE   1
  5. #define FALSE  0
  6.  
  7. /*****************/
  8. /*  main         */
  9. /**************************************************************/
  10.  
  11. main(int argc, char *argv[])
  12. {
  13. FILE *ifp, *ofp;
  14. char ch;
  15. int index=0;
  16.  
  17. if(argc != 3)
  18.   {
  19.   printf("\x07\nUsage:  %s <input text filename> <output script filename>\n\n", argv[0]);
  20.   exit(FALSE);
  21.   }
  22.  
  23. if((ifp=fopen(argv[1],"r")) == NULL)
  24.   {
  25.   printf("\x07\nCannot open %s!\n\n",argv[1]);
  26.   exit(FALSE);
  27.   }
  28.  
  29. if(ofp=fopen(argv[2],"r"))
  30.   {
  31.   printf("\x07\nFile %s already exists!\n\n",argv[2]);
  32.   fclose(ifp);
  33.   fclose(ofp);
  34.   exit(FALSE);
  35.   }
  36.  
  37. if((ofp=fopen(argv[2],"w")) == NULL)
  38.   {
  39.   printf("\x07\nCannot create %s!\n\n",argv[2]);
  40.   fclose(ifp);
  41.   exit(FALSE);
  42.   }
  43.  
  44. fputs("/* Terminus Script File */\n", ofp);
  45. fputs("/* Created with TEXT2SCP by Don Lester */\n", ofp);
  46.  
  47. while((ch=getc(ifp)) != EOF)
  48.   {
  49.   if(index==0)
  50.     fprintf(ofp, "SEND \"");
  51.  
  52.   if(ch=='\x22')
  53.     fprintf(ofp, "\\\"");
  54.   else
  55.     if(ch=='\x27')
  56.       fprintf(ofp, "\\'");
  57.   else
  58.     if(ch=='\x5C')
  59.       fprintf(ofp, "\\\\");
  60.   else
  61.     if(ch=='\xD');
  62.   else
  63.     if(ch=='\xA')
  64.       fprintf(ofp, "\\r");
  65.   else
  66.     if(ch=='\x1B')
  67.       fprintf(ofp, "\\e");
  68.   else
  69.     if(ch=='!')
  70.       fprintf(ofp, "^!");
  71.   else
  72.     if(ch=='^')
  73.       fprintf(ofp, "^^");
  74.   else
  75.     if(ch=='~')
  76.       fprintf(ofp, "^~");
  77.   else
  78.     if(ch=='\x0C')
  79.       fprintf(ofp, "\\f");
  80.   else
  81.     if(ch=='\x09')
  82.       fprintf(ofp, "\\t");
  83.   else
  84.     fprintf(ofp, "%c", ch);
  85.  
  86.   index++;
  87.  
  88.   if((index > 200) && (ch != '\xA'))
  89.     {
  90.     index=0;
  91.     fprintf(ofp, "\"\n");
  92.     }    
  93.  
  94.   if(ch=='\xA')
  95.     {
  96.     fprintf(ofp, "\"\n");
  97.     index=0;
  98.     }
  99.   }
  100. fputs("/* End of TEXT2SCP script */\n", ofp);
  101.  
  102. fclose(ifp);
  103. fclose(ofp);
  104. }
  105.